import javax.swing.*;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Person extends JFrame implements ActionListener{

	boolean done;
	JButton ok;
	JButton close;
	String fName;
	String lName;
	String mI;
	String age;
	JTextField fNameT;
	JTextField mNameT;
	JTextField lNameT;
	JTextField ageT;
	public Person()
	{
		done=false;
		fName="";
		lName="";
		mI="";
		age="";
		setLayout(new GridLayout(5, 2, 5, 5));
		JLabel fNameL= new JLabel("First Name: ");
		fNameT= new JTextField(8);
		JLabel mNameL= new JLabel("MI: ");
		mNameT= new JTextField(1);
		JLabel lNameL= new JLabel("Last Name: ");
		lNameT= new JTextField(8);
		JLabel ageL= new JLabel("Age: ");
		ageT= new JTextField(8);
		ok=new JButton("OK");
		close=new JButton("Close");
		ok.setActionCommand("OK");
		close.setActionCommand("CLOSE");
		ok.addActionListener(this);
		close.addActionListener(this);
		add(fNameL);
		add(fNameT);
		add(mNameL);
		add(mNameT);
		add(lNameL);
		add(lNameT);
		add(ageL);
		add(ageT);
		add(ok);
		add(close);
	}
	public void initialize()
	{
		this.setTitle("Person");
		this.setSize(400,300);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
	public void actionPerformed(ActionEvent event)
	{
		String command=event.getActionCommand();
		if(command=="OK")
		{
			fName=fNameT.toString();
			lName=lNameT.toString();
			mI=mNameT.toString();
			age=ageT.toString();
			done=true;
			dispose();
		}
		else if(command=="CLOSE")
		{
			dispose();
		}
	}
	public String getFName()
	{
		return fName;
	}
	public String getLName()
	{
		return lName;
	}
	public String getMI()
	{
		return mI;
	}
	public String getAge()
	{
		/*String tempAge="";
		String[] a=age.split("//-");
		for(int i=0;i<age.size();i++)
		{
			if(a[i]=="zero")
			{
				tempAge+="0";
			}
			else if(a[i]=="one")
			{
				tempAge+="1";
			}
			else if(a[i]=="two")
			{
				tempAge+="2";
			}
			else if(a[i]=="three")
			{
				tempAge+="3";
			}
			else if(a[i]=="four")
			{
				tempAge+="4";
			}
			else if(a[i]=="five")
			{
				tempAge+="5";
			}
			else if(a[i]=="six")
			{
				tempAge+="6";
			}
			else if(a[i]=="seven")
			{
				tempAge+="7";
			}
			else if(a[i]=="eight")
			{
				tempAge+="8";
			}
			else if(a[i]=="nine")
			{
				tempAge+="9";
			}
			else if(a[i]=="ten")
			{
				tempAge+="10";
			}
			else if(a[i]=="eleven")
			{
				tempAge+="11";
			}
			else if(a[i]=="twelve")
			{
				tempAge+="12";
			}
			else if(a[i]=="thirteen")
			{
				tempAge+="13";
			}
			else if(a[i]=="fourteen")
			{
				tempAge+="14";
			}
			else if(a[i]=="fifteen")
			{
				tempAge+="15";
			}
			else if(a[i]=="sixteen")
			{
				tempAge+="16";
			}
			else if(a[i]=="seventeen")
			{
				tempAge+="17";
			}
			else if(a[i]=="eighteen")
			{
				tempAge+="18";
			}
			else if(a[i]=="nineteen")
			{
				tempAge+="19";
			}
			else if(a[i]=="twenty")
			{
				tempAge+="2";
			}
			else if(a[i]=="thirty")
			{
				tempAge+="3";
			}
			else if(a[i]=="forty")
			{
				tempAge+="4";
			}
			else if(a[i]=="fifty")
			{
				tempAge+="5";
			}
			else if(a[i]=="sixty")
			{
				tempAge+="6";
			}
			else if(a[i]=="seventy")
			{
				tempAge+="7";
			}
			else if(a[i]=="eighty")
			{
				tempAge+="8";
			}
			else if(a[i]=="ninety")
			{
				tempAge+="9";
			}
			else if(a[0]=="one hundred")
			{
				tempAge="100";
			}
		}*/
		return age;//Possibly return int value based on written age
		//return tempAge;
	}
	public boolean done()
	{
		return done;
	}
	public String toString()
	{
		return getFName() + " " + getLName() + " " + getMI() + " " + getAge();
	}
}
